package com.hgw.Demo07_ObserverPattern.examples;

/**
 * Data time:2021/12/19 16:13
 * StudentID:2019112118
 * Author:hgw
 * Description: 战队成员类，充当具体观察者类
 */
public class Players implements Observer{
    private String name;

    public Players(String name) {
        this.name = name;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    // 支援盟友方法的实现
    @Override
    public void help() {
        System.out.println("坚持住，" + this.name + "来救你！");
    }

    // 遭受攻击方法的实现，当遭受攻击时将调用战队控制中心类的通知方法 notifyObserver 来通知盟友
    @Override
    public void beAttacked(AllControlCenter acc) {
        System.out.println(this.name + "被攻击！");
        acc.notifyObserver(name);
    }
}
